﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace ToolsForCMIS
{
    public class clsConnectData
    {
        string uri = string.Empty;
        public clsConnectData()
        {
            uri = "IPList.xml";
        }

        public clsConnectData(string uri)
        {
            this.uri = uri;
        }

        public DataSet GetData()
        {
            try
            {                                
                XmlReader xmlFile;
                XmlReaderSettings settingsOk = new XmlReaderSettings();
                settingsOk.CloseInput = true;
                //settingsOk.Async = true;                
                xmlFile = XmlReader.Create(uri, settingsOk);
                DataSet ds = new DataSet("IPList");
                ds.ReadXml(xmlFile);                
                xmlFile.Close();
                //xmlFile.Dispose();
                return ds;
            }
            catch (Exception ex)
            {
                return null;
            }
            
        }
        public DataSet GetData(string strUri)
        {
            try
            {
                //XmlReader xmlFile;
                XmlReaderSettings settingsOk = new XmlReaderSettings();
                settingsOk.CloseInput = true;
                //settingsOk.Async = true;
                using (var xmlFile = XmlReader.Create(strUri, settingsOk))
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(xmlFile);
                    xmlFile.Close();
                    //xmlFile.Dispose();
                    return ds; 
                }             
            }
            catch (Exception ex)
            {
                return null;
            }

        }

        public string SaveDataXml(string strUri)
        {
            return "";
        }
    }


}
